package com.shell.customer.register.rx;

import com.shell.bee.base.utils.StringUtil;
import com.shell.customer.invitation.service.InvtCusService;
import com.shell.customer.po.CusInvt;
import com.shell.customer.register.RegisterEvent;
import com.shell.customer.register.vo.RegisterVo;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UpdateCusInvtSubscriber extends OnErrorNotImplementedSubscriber<RegisterEvent> {
	@Autowired
	private InvtCusService invtCusService;

	public void onApplicationEvent(RegisterEvent event) {
		RegisterVo registerVo = event.getRegisterVo();
		List<CusInvt> cusInvts = this.invtCusService.getCusInvtByCusName(registerVo.getCusName());
		for (CusInvt invt : cusInvts) {
			if (StringUtil.empty(invt.getInviteeId())) {
				invt.setInviteeId(registerVo.getCusId());
				this.invtCusService.updateAll(invt);
			}
		}
	}
}
